package net.uhuijia.zb.userzhubolivegood.controller;

import net.uhuijia.enums.MoreInfo;
import net.uhuijia.utils.IticConst;
import net.uhuijia.vo.ResultMapVo;
import net.uhuijia.vo.ReturnListVo;
import net.uhuijia.vo.good.GoodZBListVo;
import net.uhuijia.vo.zb.OnlineLiveGoodVo;
import net.uhuijia.zb.userzhubolivegood.persistence.model.UserZhuboLiveGood;
import net.uhuijia.zb.userzhubolivegood.persistence.model.UserZhuboLiveGoodExample;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import net.uhuijia.appbase.controller.BaseController;
import net.uhuijia.zb.userzhubolivegood.service.UserZhuboLiveGoodService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
@RequestMapping(value="/userzhubolivegood")
public class UserZhuboLiveGoodController
     extends BaseController<UserZhuboLiveGoodService,UserZhuboLiveGood,UserZhuboLiveGoodExample> {
    @Autowired
    private UserZhuboLiveGoodService userZhuboLiveGoodService;

    /**
     * 直播间右侧商品列表
     * @param liveId
     * @param request
     * @return
     */
    @RequestMapping(value = "onlineLiveGoodList" ,method = RequestMethod.GET)
    @ResponseBody
    public ResultMapVo<ReturnListVo<GoodZBListVo>> onlineLiveGoodList(String liveId, HttpServletRequest request){
        if(StringUtils.isEmpty(liveId))
            throw new IllegalArgumentException();
        UserZhuboLiveGoodExample example = new UserZhuboLiveGoodExample();
        IticConst.handlePageQueryDefault(request,example);
        List<GoodZBListVo> goodZBListVos = this.userZhuboLiveGoodService.onlineLiveGoodList(liveId,example);
        int count = this.userZhuboLiveGoodService.findUserZhuboLiveGoodCountByLiveIdAndPage(liveId);
        MoreInfo moreInfo = IticConst.isMore(request,count);
        ReturnListVo<GoodZBListVo> returnListVo = new ReturnListVo<>(goodZBListVos,count,moreInfo);
        return ResultMapVo.ok(returnListVo);
    }




}